00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00052 define("PATH_TO_ROOT", "../");
00054 require_once (PATH_TO_ROOT."common/init.inc.php");
00055 if (isset($_POST['Cancel'])) {
00056 header("Location: ".$_SERVER['PHP_SELF']);
00057 exit;
00058 }
00060 require_once (PATH_TO_ROOT."common/header.inc.php");
00061 include_once "./classes/class.header.inc.php";
00062 include_once "./classes/class.photofunctions.inc.php";
00063 include_once "header.inc.php";
00064 writeContentHeader("Suchformular");
00065 $config['hitsperpage'] = 20;
00066 $navpath.= "<a class=\"bglink\" href=\"".build_link("search.php") ."\" title='Suche'>Suche</a>";
00067 $course = $_SESSION['course'];
00068 $user = $_SESSION['usergroup'];
00069 if (isset($startsearch) && $startsearch) {
00070 if ($course != 1) {
00071 $abfrage = "SELECT boardid FROM forum_board WHERE boarddisabled='0' AND is_photogallery=1 AND categoryid=".$course;
00072 } else {
00073 $abfrage = "SELECT boardid FROM forum_board WHERE boarddisabled='0' AND is_photogallery=1";
00074 }
00075 $a_board = array();
00076 $r_board = forum_query($abfrage);
00077 while ($board = mysql_fetch_array($r_board)) {
00078 $a_board[] = $board['boardid'];
00079 }
00080 if (empty($a_board)) {
00081 errormessage('Fehler', 'Es sind keine Boards angelegt.');
00082 }
00083 $a_boardlist = array();
00084 if (!isset($selectedboards) || $selectedboards[0] == 0) {
00085
00086 $selectedboards = $a_board;
00087 }
00088 while (list(, $boardid) = each($selectedboards)) {
00089 $P->set_boardid($boardid);
00090 if ($boardid != -1 && getAlbumRight('view', $boardid) == true) {
00091 if (in_array($boardid, $a_board)) {
00092 $a_boardlist[] = $boardid;
00093 }
00094 }
00095 }
00096 $boards = implode(',', $a_boardlist);
00097 if (empty($boards)) {
00098 errormessage('Fehler', 'Es gibt keine Alben/Bilder die sie durchsuchen können.');
00099 }
00100 if (!isset($page)) {
00101 $page = 0;
00102 }
00103 $where = array();
00104 $where[] = "(post.threadid=thread.threadid)";
00105 $where[] = "(thread.boardid IN (".addslashes($boards) ."))";
00106 if (isset($repliesonly) && $repliesonly == "yes") {
00107 $where[] = "(thread.threadreplies>0)";
00108 }
00109 if (isset($period) && $period == "yes") {
00110 $searchstart = mktime(0, 0, 0, $startmonth, 1, $startyear);
00111 $searchend = mktime(0, 0, 0, $endmonth+1, 0, $endyear);
00112 $where[] = "(thread.threadtime>$searchstart AND thread.threadtime<$searchend)";
00113 }
00114 if ($searchfor == "post") {
00115 $a_words = explode(" ", $words);
00116 $sqlwords = array();
00117 while (list($key, $val) = each($a_words)) {
00118 if (strlen($val) < 3) {
00119 errormessage("Fehler", "Sie können nicht nach Wörtern mit weniger als 3 Zeichen suchen.");
00120 }
00121 if ($key > 5) {
00122 errormessage("Fehler", "Sie können maximal nach 6 Wörtern suchen.");
00123 }
00124 if ($config['slow_search']) $sqlwords[] = "INSTR(LOWER(post.posttext),LOWER('".addslashes($val) ."'))>0";
00125 else $sqlwords[] = "INSTR(post.posttext,'".addslashes($val) ."')>0";
00126 }
00127 $where[] = '('.implode(' '.($searchmethod == 'OR' ? 'OR' : 'AND') .' ', $sqlwords) .')';
00128 } elseif ($searchfor == "author") {
00129
00130
00131 $r_user = forum_query("SELECT userID, username FROM forum_user WHERE LOWER(username)=LOWER('".addslashes($words) ."')");
00132 $user = mysql_fetch_array($r_user);
00133
00134 if (!$user['userID'] && $user['username'] != 'Anonymous') {
00135 errormessage("Fehler", "Der Autor nach dem Sie suchen wollen existiert nicht!");
00136 }
00137
00138 $where[] = "(post.userID='$user[userID]')";
00139 } elseif ($searchfor == "today") {
00140 $where[] = "(thread.threadtime)>".(time() -(60*60*24));
00141 } elseif ($searchfor == "lastthreads") {
00142 $where[] = "(thread.threadtime)>".(time() -(60*60*24*intval($days)));
00143 } else {
00144 $a_words = explode(" ", $words);
00145 $sqlwords = array();
00146 while (list($key, $val) = each($a_words)) {
00147 if (strlen($val) < 3) {
00148 errormessage("Fehler", "Sie können nicht nach Wörtern mit weniger als 3 Zeichen suchen.");
00149 }
00150 if ($key > 5) {
00151 errormessage("Fehler", "Sie können maximal nach 6 Wörtern suchen.");
00152 }
00153 if ($config['slow_search']) $sqlwords[] = "INSTR(LOWER(thread.threadtopic),LOWER('".addslashes($val) ."'))>0";
00154 else $sqlwords[] = "INSTR(thread.threadtopic,'".addslashes($val) ."')>0";
00155 }
00156 $where[] = '('.implode(' '.($searchmethod == 'OR' ? 'OR' : 'AND') .' ', $sqlwords) .')';
00157 }
00158
00159
00160 $query = "
00161 SELECT DISTINCT
00162 thread.threadid AS hits
00163 FROM
00164 forum_thread AS thread,
00165 forum_post AS post
00166 WHERE
00167 ".implode(" AND ", $where) ."
00168 LIMIT 100";
00169 $r_presearch = forum_query($query);
00170 $resultcount = mysql_num_rows($r_presearch);
00171
00172 $query = "
00173 SELECT DISTINCT
00174 thread.threadid,
00175 thread.threadtopic,
00176 thread.boardid,
00177 thread.threadtime,
00178 thread.threadlastreplyby,
00179 thread.threadauthor,
00180 thread.threadreplies
00181 FROM
00182 forum_thread AS thread,
00183 forum_post AS post
00184 WHERE
00185 ".implode(" AND ", $where) ."
00186 ORDER BY
00187 thread.threadtime DESC LIMIT ".$page*$config['hitsperpage'].", ".$config['hitsperpage'];
00188 $r_search = forum_query($query);
00189 if ($error = mysql_error()) {
00190 errormessage("Fehler", "Fehler");
00191 }
00192 if (mysql_num_rows($r_search) == 0) {
00193 message("Keine Themen gefunden", "Es wurden keine Themen gefunden die Ihren Suchkriterien entsprechen!<br/><a href=\"".build_link("search.php") ."\" title='neue Suche'>Neue Suche</a>");
00194 }
00195 $r_board = forum_query("
00196 SELECT
00197 board.boardid, board.boardname, category.categoryname
00198 FROM
00199 forum_board AS board,
00200 forum_category AS category
00201 WHERE
00202 board.categoryid=category.categoryid AND board.is_photogallery=1");
00203 while ($board = mysql_fetch_array($r_board)) {
00204 $boardpath[$board['boardid']] = $board['categoryname'].' / '.$board['boardname'];
00205 }
00206 $frame = new Template("templates/frame.html");
00207 $searchresult = new Template("templates/searchresult.html");
00208 $searchresultrow = new Template("templates/searchresultrow.html");
00209 $pages = ceil($resultcount/$config['hitsperpage']);
00210 $pagesstring = "";
00211 for ($i = 0 ; $i < $pages ; $i++) {
00212 if ($i == $page) {
00213 $pagesstring.= ">".($i+1) ."< ";
00214 } else {
00215 $pagesstring.= '[<a href="'.build_link('search.php?page='.$i.'&searchfor='.$searchfor.'&words='.((isset($words)) ? $words : '') .'&searchmethod='.((isset($searchmethod)) ? $searchmethod : '') .'&repliesonly='.((isset($repliesonly)) ? $repliesonly : '') .'&period='.((isset($period)) ? $period : '') .'&startmonth='.((isset($startmonth)) ? $startmonth : '') .'&startyear='.((isset($startyear)) ? $startyear : '') .'&endmonth='.((isset($endmonth)) ? $endmonth : '') .'&endyear='.((isset($endyear)) ? $endyear : '') .'&days='.((isset($days)) ? $days : ''));
00216 reset($selectedboards);
00217 while (list(, $selectedboard) = each($selectedboards)) {
00218 $pagesstring.= '&selectedboards[]='.$selectedboard;
00219 }
00220 $pagesstring.= '&startsearch=1">'.($i+1) .'</a>] ';
00221 }
00222 }
00223 $RESULT_ROWS = '';
00224 while ($search = mysql_fetch_array($r_search)) {
00225 $i++;
00226 if ($i%2 > 0) {
00227 $rowbgcolor = "class='cellText'";
00228 } else {
00229 $rowbgcolor = "class='cellTextDark'";
00230 }
00231 $search['threadtopic'] = Data::toHTML($search['threadtopic'], false);
00232 $search['threadauthor'] = Data::toHTML($search['threadauthor'], false);
00233 $search['threadlastreplyby'] = Data::toHTML($search['threadlastreplyby'], false);
00234 $search['threadtime'] = form_date($search['threadtime']);
00235 $search['threadpath'] = Data::toHTML($boardpath[$search['boardid']], false);
00236 $highlight = (((!empty($a_words)) && (count($a_words))) ? '&highlight='.urlencode(implode(' ', $a_words)) : '');
00237 eval($searchresultrow->GetTemplate("RESULT_ROWS"));
00238 }
00239 $navpath.= ' » Suchergebnisse';
00240 if ($resultcount == 100) $resultcount = '</strong>Es wurden sehr viele Suchergebnisse gefunden, bitte versuchen Sie, die Suche weiter einzuschränken.<br/><strong>'.$resultcount;
00241 eval($searchresult->GetTemplate("CONTENT"));
00242 eval($frame->GetTemplate());
00243 } else {
00244
00245 $a_board = array();
00246 $r_board = forum_query("SELECT boardname, boardid, categoryid FROM forum_board WHERE boarddisabled='0' AND is_photogallery=1 ORDER BY boardorder ASC");
00247 while ($board = mysql_fetch_array($r_board)) {
00248 $P->set_boardid($board['boardid']);
00249 if (getAlbumRight('view', $board['boardid'])) {
00250 $a_board[$board['categoryid']][] = $board;
00251 }
00252 }
00253 $boards = '';
00254 $r_category = forum_query("SELECT categoryname, categoryid FROM forum_category ORDER BY categoryorder ASC");
00255 while ($category = mysql_fetch_array($r_category)) {
00256 if ($user != 1) {
00257 if ($course == $category['categoryid']) {
00258 if (isset($a_board[$category['categoryid']])) {
00259 $boards.= '<option value="0">'.Data::toHTML($category['categoryname'], false) .'</option>';
00260 while (list(, $board) = @each($a_board[$category['categoryid']])) {
00261 $boards.= '<option value="'.$board['boardid'].'">- '.Data::toHTML($board['boardname'], false) .'</option>';
00262 }
00263 }
00264 }
00265 } else {
00266 if (isset($a_board[$category['categoryid']])) {
00267 $boards.= '<option value="0">'.Data::toHTML($category['categoryname'], false) .'</option>';
00268 while (list(, $board) = @each($a_board[$category['categoryid']])) {
00269 $boards.= '<option value="'.$board['boardid'].'">- '.Data::toHTML($board['boardname'], false) .'</option>';
00270 }
00271 }
00272 }
00273 }
00274 $getdate = getdate(time());
00275 $Tframe = new Template("templates/frame.html");
00276 $Tsearchform = new Template("templates/searchform.html");
00277 $navpath.= ' » Sucheinstellungen';
00278 eval($Tsearchform->GetTemplate("CONTENT"));
00279 eval($Tframe->GetTemplate());
00280 }
00281 require_once "footer.inc.php";
00283 require_once (PATH_TO_ROOT."common/footer.inc.php");
00284 ?>